/**
 * 快速排序最简版
*/

const quickSort = arr => {
  if (arr.length <= 1) return arr
  const mid = ~~(arr.length / 2),
    pivod = arr[mid],
    left = arr.filter((num, index) => {
      if (index !== mid) {
        return num <= pivod
      }
    }),
    right = arr.filter(num => num > pivod)

  return [...quickSort(left), pivod, ...quickSort(right)]
}

const majorityElement = nums => {
  nums = quickSort(nums)
  return nums[parseInt(nums.length / 2)]
}
// console.log(quickSort([3, 2, 3, 1, 1, 2, 2]))

console.log(majorityElement(arr))